<!--
 * @Author: 袁三金
 * @Date: 2023-10-18 16:13:53
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-10-21 19:39:30
 * @Description: 三级菜单展示组件
-->
<template>
    <div>
        <el-card>
            <el-form ref="formRef" label-width="auto" :inline="true">
                <el-form-item label="一级分类" prop="name">
                    <el-select :disabled="scene==0?false:true" v-model="categoryStore.C1ID" @change="handler1">
                        <!-- label即为标签展示的数据；value即为select收集的数据 -->
                        <el-option v-for="(c1) in categoryStore.C1Arr" :key="c1.id" :label="c1.name"
                            :value="c1.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="二级分类" prop="name">
                    <el-select :disabled="scene==0?false:true" v-model="categoryStore.C2ID" @change="handler2">
                        <!-- label即为标签展示的数据；value即为select收集的数据 -->
                        <el-option v-for="(c2) in categoryStore.C2Arr" :key="c2.id" :label="c2.name"
                            :value="c2.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="三级分类" prop="name">
                    <el-select :disabled="scene==0?false:true" v-model="categoryStore.C3ID" @change="handler3">
                        <!-- label即为标签展示的数据；value即为select收集的数据 -->
                        <el-option v-for="(c3) in categoryStore.C3Arr" :key="c3.id" :label="c3.name"
                            :value="c3.id"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
        </el-card>
    </div>
</template>

<script setup lang="ts">
import { onMounted } from 'vue';
import useCategoryStore from '@/store/modules/category'
let categoryStore = useCategoryStore();
onMounted(() => {
    getC1();
})
const getC1 = () => {
    // 通知仓库获取一级路由的数据
    categoryStore.getC1()
};
// 获取二级分类数据（一级分类改变时触发）
const handler1 = () => {
// 一级分类数据发生变化需要清空二级三级数据
    categoryStore.C2Arr = [];
    categoryStore.C2ID = '';
    categoryStore.C3ID = '';
    categoryStore.C3Arr = [];
    categoryStore.getC2();
};
// 获取三级分类数据(二级分类改变触发)
const handler2 = () => {
    categoryStore.C3ID = '';
    categoryStore.C3Arr = [];
    categoryStore.getC3();
};
// 三级分类改变时触发,获取已有属性数据
const handler3 = ()=>{
    categoryStore.AttrList = [];
};
// 接收父组件传过来的值
defineProps(['scene']);
</script>

<style scoped></style>